package com.mall.admin.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.commons.utils.PageResult;
import com.mall.domain.PmsProductAttributeCategory;
import com.mall.interface1.api.PmsProductAttributeCategoryApi;
import com.mall.vo.PmsProductAttributeVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PmsProductAttributeCategoryService {

    @DubboReference
    private PmsProductAttributeCategoryApi pmsProductAttributeCategoryApi;

    /**
     * 添加商品属性分类
     *
     * @param name
     * @return
     */
    public void create(String name) {
        pmsProductAttributeCategoryApi.create(name);
    }

    /**
     * 获取所有商品属性分类及其下属性
     *
     * @return
     */
    public List<PmsProductAttributeVo> listWithAttr() {
        List<PmsProductAttributeVo> list = pmsProductAttributeCategoryApi.listWithAttr();
        return list;
    }


    /**
     * 分页获取所有商品属性分类
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageResult list(Integer pageNum, Integer pageSize) {
        //PageResult pageResult = new PageResult();
        Page<PmsProductAttributeCategory> page = pmsProductAttributeCategoryApi.listAttribute(pageNum, pageSize);
        return new PageResult(pageNum, pageSize, (int) page.getTotal(), page.getRecords());
    }


    /**
     * 删除单个商品属性分类
     *
     * @param id
     * @return
     */
    public void deleteById(Long id) {
        pmsProductAttributeCategoryApi.deleteById(id);
    }

    /**
     * 修改商品属性分类
     *
     * @param id
     * @param name
     */
    public void updateById(Long id, String name) {
        pmsProductAttributeCategoryApi.updateById(id,name);
    }

    /**
     * 获取单个商品属性分类信息
     * @param id
     * @return
     */
    public PmsProductAttributeCategory attributeCategoryById(Long id) {
        PmsProductAttributeCategory category=pmsProductAttributeCategoryApi.attributeCategoryById(id);
        return category;
    }
}
